import TreeNode from TreeNode


/*
    可以优化,懒得写~
*/


/**
 * @param {TreeNode} root
 * @return {number[]}
 */
var inorderTraversal = function(root) {
    let list = []
    let cur = root
    while(cur){
        if(cur.left===null){
            list.push(cur.val)
            cur = cur.right
        }else{
            let tmp = cur.left
            while(tmp.right!==null&&tmp.right!==cur)tmp=tmp.right
            if(tmp.right===null){
                tmp.right = cur
                cur = cur.left
            }else{
                tmp.right=null
                list.push(cur.val)
                cur = cur.right
            }
        }
    }
    return list
};